public class Leecode100 {
    /**
     * 相同的树
     *
     */
    public class TreeNode1 {
        int val;
         TreeNode1 left;
         TreeNode1 right;
        TreeNode1() {}
        TreeNode1(int val) { this.val = val; }
        TreeNode1(int val, TreeNode1 left, TreeNode1 right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
        //依旧是深度优先算法，重点是找到判断递归的循环终止条件
    public boolean isSameTree(TreeNode1 p, TreeNode1 q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        } else if (p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }
    }
}
